<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<?=site_url('admini') ?>">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">分类管理</span></div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="<?=site_url('admini/sort/create')?>"><i class="icon-font"></i>新增分类</a>
                        <a id="batchDel" href="javascript:void(0)" onclick="del_all()"><i class="icon-font"></i>批量删除</a>
                        <!-- <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a> -->
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" id="all" type="checkbox" onclick="check_all()"></th>
                            <th width="5%">排序</th>
                            <th>ID</th>
                            <th width="40%">分类名称</th>
                            <th width="30%">描述</th>
                            <th>操作</th>
                        </tr>
                        <?php foreach($list as $k => $v): ?>
                        <tr id="list_<?=$v['id'] ?>" class="top_0">
                            <td class="tc"><input name="checkbox" value="<?=$v['id']?>" type="checkbox"></td>
                            <td>
                                <input class="common-input sort-input" value="<?=$v['sort']?>" type="text" onclick="setsort(<?=$v['id']?>)">
                            </td>
                            <td><?=$v['id'] ?></td>
                            <td title="点击查看下级分类" onclick="getlow('<?=$v['id'] ?>')"><a href="#" title="<?=$v['name'] ?>"><?=$v['name'] ?></a> </td>
                            <td><?=$v['depict']?></td>
                            <td>
                            	<a class="link-update" href="<?=site_url('admini/Attribute/action?sid='.$v['id']) ?>">分类属性</a>
                                <a class="link-update" href="<?=site_url('admini/sort/update/'.$v['id']) ?>">修改</a>
                                <a class="link-del" href="javascript:del_sort(<?=$v['id']?>)">删除</a>
                            </td>
                        </tr>
                        <?php endforeach;?>

<!--                        <tr>
                            <td class="tc"><input name="id[]" value="59" type="checkbox"></td>
                            <td>
                                <input name="ids[]" value="59" type="hidden">
                                <input class="common-input sort-input" name="ord[]" value="0" type="text">
                            </td>
                            <td>59</td>
                            <td title="发哥经典"><a href="#" title="发哥经典">　　|—　发哥经典</a> </td>
                            <td>
                                <a class="link-update" href="#">修改</a>
                                <a class="link-del" href="#">删除</a>
                            </td>
                        </tr>-->
                    </table>
                    <!-- <div class="list-page"> 2 条 1/1 页</div> -->
                </div>
            </form>
        </div>
<script>

    function getlow(pid){
        if(pid > 0){
            $.post("<?=site_url('admini/sort/getsort')?>",{sid:pid},function(data){
                var l = '';
                $(data).each(function(){
                    var name = '';
                    for(var i = 1 ; i <= this.top ; i ++ ){
                        name += '　|—　';
                    }
                    l += sethtml(this.id,name+this.name,this.depict,this.sort,this.top);
                    for(i = this.top;i < 5 ; i ++){
                    	$('.top_'+i).remove();
                    }
                });

                $('#list_'+pid).after(l);
            },'json');
        }
    }

    //设置html字符串
    function sethtml(id,name,depice,sort,top){
        var l = '';
        l += '<tr id="list_'+id+'" class="top_'+top+'">';
        l += '<td class="tc"><input name="checkbox" value="'+id+'" type="checkbox"></td>';
        l += '<td>';
        l +=     '<input class="common-input sort-input" name="ord[]" value="'+sort+'" type="text" onclick="setsort('+id+')">';
        l += '</td>';
        l += '<td>'+id+'</td>';
        l += '<td title="点击查看下级分类" onclick="getlow('+id+')"><a href="#" title="'+name+'">'+name+'</a> </td>';
        l += '<td>'+depice+'</td>'
        l += '<td>';
        l += '<a class="link-update" href="<?=site_url("admini/Attribute/action") ?>?sid='+id+'">分类属性</a>'
        l +=    ' <a class="link-update" href="<?=site_url()?>/admini/sort/update/'+id+'.html">修改</a>';
        l +=     '<a class="link-del" href="javascript:del_sort('+id+')">删除</a>';
        l += '</td>';
        l += '</tr>';
        return l ;
    }

    //设置分类排序
    layer.config({
	    extend: 'extend/layer.ext.js'
	});
    function setsort(sort){

		layer.prompt({
		    title: '输入数值，越大越靠前',
		    formType: 0 //prompt风格，支持0-2
		}, function(val){
		    $.post("<?=site_url('admini/sort/set_sort')?>",{sid:sort,sort:val},function(data){
		    	if(data == 1){
		    		layer.alert('修改排序成功，刷新可查看效果',{
	                    icon:1,
	                });
		    	}else{
		    		layer.alert(data,{
	                    icon:2,
	                });
		    	}
		    })
		});
    }

    //分类删除
    function del_sort(id){
    	layer.confirm('确定要删除这个分类以及该分类下的所有分类吗？', {
    		icon:0,
		    btn: ['删除','取消'], //按钮
		    shade: false //不显示遮罩
		}, function(){
		    $.post("<?=site_url('admini/sort/del_sort')?>",{sid:id},function(res){
		    	if(res == 1){
		    		location.reload(true);
		    	}else{
		    		layer.alert(res,{
	                    icon:2,
	                });
		    	}
		    })
		});
    }

    //分类选中
    function check_all(){
        var v = $('#all').is(':checked');
        $("input[name='checkbox']:checkbox").each(function() {
            this.checked=v;
        })
    }

    //批量删除
    function del_all(){
        layer.confirm('删除之后不能恢复，需要继续吗？', {
            icon:0,
            btn: ['删除','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            $("input[name='checkbox']").each(function() {
                if($(this).is(':checked')){
                    var v = $(this).val();
                    $.ajax({
                        url:"<?=site_url('admini/sort/del_sort')?>",
                        type:"post",
                        async:false,
                        data:{sid:v}
                    });
                }
            })
            location.reload(true);
        });
    }

</script>